﻿<CodeSnippetTabbed DocLink="https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxUpload#multiple-file-upload">
<CodeSnippetTabPage Text="Razor">@(@"@inject NavigationManager NavigationManager

<DxUpload Name=""myFile"" UploadUrl=""@GetUploadUrl(""api/Upload/UploadFile/"")""
    AllowMultiFileUpload=""true"" MaxFileSize=""15000000"">
</DxUpload>

@code {
    protected string GetUploadUrl(string url) {
        return NavigationManager.ToAbsoluteUri(url).AbsoluteUri;
    }
}")
</CodeSnippetTabPage>
<CodeSnippetTabPage Text="UploadController" Language="csharp">@(@"[Route(""api/[controller]"")]
public class UploadController : ControllerBase {
    private readonly IWebHostEnvironment _hostingEnvironment;

    public UploadController(IWebHostEnvironment hostingEnvironment) {
        _hostingEnvironment = hostingEnvironment;
    }

    [HttpPost(""[action]"")]
    public ActionResult UploadFile(IFormFile myFile) {
        try {
            var path = Path.Combine(_hostingEnvironment.WebRootPath, ""uploads"");
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);

            using (var fileStream = System.IO.File.Create(Path.Combine(path, myFile.FileName))) {
                myFile.CopyTo(fileStream);
            }
        } catch {
            Response.StatusCode = 400;
        }

        return new EmptyResult();
    }
}")
</CodeSnippetTabPage>
</CodeSnippetTabbed>
